﻿$(document).ready(function () {
    var glasswrapper = $('#glasswrapper');
    var glass = $('#DialogGlass');
    $("button").button();

    $('#recoverPassForm').dialog({ autoOpen: false, minWidth: 450, minHeight: 240, resizable: false, close: function (event, ui) { glasswrapper.hide(); } })
    $('.passwordbox').focus();
    $('#lnkPassRecover').click(function () {
        glass.css({ height: $('.external').height(), width: $('.external').width() });
        glasswrapper.show();
        $('#recoverPassForm').dialog('open');
        $('#rcvr_email').val($('.loginbox ').val());
        //        if ($('#txtUserName').val().length <= 0) {
        //            alert('Please put in your Username (Email address) and click the "Forgot your password" again.');
        //        }
        //        else {
        //            ResetPassword("Lost");
        //        }
        return false;
    });

    $('#btn_rcvr_cancel').click(function () {
        $('#recoverPassForm').dialog('close');
        return false;
    });
    $('#btn_rcvr_send').click(function () {
        var frmrcvrvalid = false;
        frmrcvrvalid = $('#recoverPassForm').jVal({ style: 'cover', padding: 3, border: 1, wrap: true });
        if (frmrcvrvalid) {

            ResetPassword();
        }
        return false;
    });

    ResetPassword = function () {
        var params = '{email:"' + $('#rcvr_email').val() + '", origination:"Lost"}';
        $('#recoverPassForm').dialog('close');
        $.ajax({
            type: "POST",
            contentType: "application/json; charset=utf-8",
            url: "/Service/Services.aspx/ResetPassword",
            data: params,
            dataType: "json",
            success: function (data, textStatus) {
                var jsonresult = jQuery.parseJSON(data.d);
                if (jsonresult.errorMessage == '') {
                    alert('Reset sucessfully');

                }
            },
            error: function (data, textStatus) {
                alert("Sorry.  There was an error recovering your password.  Please contact your administrator.");
                $('#recoverPassForm').dialog('open');
            }
        });
    }


});